// 导入 express
const express = require("express");
// 创建路由对象
const router = express.Router();
const multer = require('multer')
const path = require('path')
const upload = multer({ dest: path.join(__dirname, '../uploads') })
const expressJoi = require("@escook/express-joi");
// 导入文章分类的验证模块
const {
  update_cate_schema,
  add_cate_schema,
  delete_cate_schema,
  add_article_schema
} = require("../schema/artcate");

const artcate_handler = require("../router_handler/artcate");
// 获取文章分类的列表数据
router.get("/cates", artcate_handler.getArticleCates);
router.post(
  "/addcates",
  expressJoi(add_cate_schema),
  artcate_handler.addArticleCates
);
router.get(
  "/deletecate/:id",
  expressJoi(delete_cate_schema),
  artcate_handler.deleteCateById
);
router.get(
  "/cates/:id",
  expressJoi(delete_cate_schema),
  artcate_handler.getArticleById
);
router.post(
  "/updatecate",
  expressJoi(update_cate_schema),
  artcate_handler.updateCateById
);
router.post(
  "/add",
  upload.single("cover_img"),
  expressJoi(add_article_schema),
  artcate_handler.addArticle
);

// 向外共享路由对象
module.exports = router;
